package id.mankel.commons.security.shiro;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.cache.MapCache;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Mankel
 */
@Slf4j
public class RedisCacheManager implements CacheManager {

    @Autowired
    private RedissonClient redissonClient;

    @Override
    public <K, V> Cache<K, V> getCache(String s) throws CacheException {
        log.debug("CacheManager: {}", s);
        return new MapCache<>(s, this.redissonClient.getMap(s));
    }
}
